package crypt_kicker;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.TreeMap;

class Test implements Runnable
{
	static String ReadLn(int maxLength)
	{  
        byte line[] = new byte [maxLength];
        int length = 0;
        int input = -1;
        try{
            while (length < maxLength){
                input = System.in.read();
                if ((input < 0) || (input == '\n')) break; 
                line [length++] += input;
            }

            if ((input < 0) && (length == 0)) return null;  
            return new String(line, 0, length);
        }catch (IOException e){
            return null;
        }
    }
	
	public static void main(String [] args)
	{
		Test work = new Test();
		
		work.run();
	}
	
	public void run()
	{
		new WorkingStuff().run();
	}
}

class WorkingStuff implements Runnable
{
	static boolean DONE = false;
	
	public void run()
	{
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String [] dictionary;
		String [] encryption;
		String [] solArray;
		
		try
		{
				line = reader.readLine();
				int value = Integer.parseInt(line);
				int count = 0;
				
				dictionary = new String[value];
				
				while (count < value)
				{
					line = reader.readLine();
					
					dictionary[count] = line;
					
					count++;
				}
				
				while ((line = reader.readLine()) != null)
				{
				TreeMap<String, String> aMap = new TreeMap<String, String>();
				TreeMap<String, String> edMap = new TreeMap<String, String>();
					
				encryption = line.split(" ");

				solArray = new String[encryption.length + 1];

				for (int i = 0; i < encryption.length; i++) 
				{
					String word = encryption[i];
					edMap.put(word, null);

					for (int x = 0; x < word.length(); x++) 
					{
						String ch = word.substring(x, x + 1);

						if (!aMap.containsKey(ch)) {
							aMap.put(ch, null);
						}
					}
				}

				cryptTrack(solArray, 0, dictionary, encryption, aMap, edMap);

				if (DONE == false) 
				{
					for (int i = 0; i < encryption.length; i++) 
					{
						int length = encryption[i].length();

						for (int j = 0; j < length; j++) 
						{
							System.out.print("*");
						}

						System.out.print(" ");
					}
					DONE = true;
				}
				//	System.out.println();
				}
				
		} catch (IOException ex) {
			ex.printStackTrace();
		}
	}
	
	void cryptTrack(String [] sArray, int k, String [] dictionary, String [] encryptList, 
			TreeMap<String, String> alphaMap, TreeMap<String, String> edMap)
	{
		// Construct candidates (variable size). 
		String [] candidates = new String[dictionary.length];
		
		String word = "";
		
		if (k < encryptList.length)
		{
			word = encryptList[k];
		}
		
		int numberOfCandidates;
		
		boolean result = false;
		
		if (isSolution(sArray,k,alphaMap))
			printSolution(sArray);
		else 
		{
			k++;
			
			numberOfCandidates = constructCandidates(candidates, k, encryptList, dictionary, edMap, word);
			
			for (int index = 0; index < numberOfCandidates; index++)
			{
				sArray[k] = candidates[index];
				
				result = makeMove(sArray, k, word, alphaMap, edMap);
				
				if (result == true)
				{
					cryptTrack(sArray,k, dictionary, encryptList, alphaMap, edMap);
				} else {
					unMakeMove(sArray, k, word, encryptList, alphaMap, edMap); 
				}
				
				if (DONE)
				{
					break;
				}
			}
		}
		
	
	}

	int constructCandidates(String[] candidates, int k, String [] encryptList, 
			String[] dictionary, TreeMap<String,String> edMap, String encryptWord) 
	{
		int x = 0;
		String key = "";
		
		for (int i = 0; i < dictionary.length; i++)
		{
			if (dictionary[i].length() == encryptWord.length())
			{
				key = findValues(edMap, encryptList, dictionary[i], k);
				
				if (key.equals(encryptWord) || key.equals("") && checkDuplicates(dictionary[i], encryptWord))
				{
					candidates[x] = dictionary[i];
					x++;
				}
			}
		}
		
		if (x == 0)
		{
			DONE = false;
		}
		
		return x;
	}
	
	String findValues(TreeMap<String, String> map, String [] eList, String value, int k)
	{
		String key = "";
		
		for (int i = 0; i < k; i++)
		{
			String result = map.get(eList[i]);
			
			if (result != null)
			{
				if (result.equals(value))
				{
					key = eList[i];
					break;
				}
			}
		}
		
		return key;
	}
	
	boolean checkDuplicates(String word, String encryption)
	{
		TreeMap<String, String> tempMap= new TreeMap<String, String>();
		
		tempMap.put(encryption.substring(0, 0+1), word.substring(0, 0+1));
		
		boolean result = true;
		
		for (int i = 1; i < word.length(); i++)
		{
			String eWord = encryption.substring(i, i+1);
			
			if (eWord.equals(encryption.subSequence(0,  0+1)))
			{
				String value = tempMap.get(encryption.substring(0, 0+1));
				
				if (!value.equals(word.substring(i, i+1)))
				{
					result = false;
					break;
				}
			}	
		}
		
		return result;
	}
	
	boolean makeMove(String [] solArray, int k, String eWord, TreeMap<String, String> map, TreeMap<String, String> edMap)
	{
		// Verify that the elements in solution array has a correct one-to-one mapping with the tree map.
		String word = solArray[k];
		
		boolean result = true;
		
		for (int index = 0; index < word.length(); index++)
		{
			// Take the character of the selected dictionary word.
			String character = word.substring(index, index + 1);
			
			// Take the character of the encryption word.
			String eCharacter = eWord.substring(index, index + 1);
			
			// Retrieve value using character of encryption word as key.
			String value = map.get(eCharacter);
			
			if (value != null)
			{
				if (value.equals(character))
				{
					result = true;
				} 
				else 
				{
					return !result;
				}
			} 
		}
		
		if (result == true)
		{
			// Map the characters.
			for (int index = 0; index < word.length(); index++)
			{
				// Take the character of the encryption word.
				String eCharacter = eWord.substring(index, index + 1);
				
				// Take the character of the selected dictionary word.
				String character = word.substring(index, index + 1);
				
				map.put(eCharacter, character);
				edMap.put(eWord, word);
			}
		}
			return result;
	}
	
	void unMakeMove(String [] solArray, int k , String word, String [] encryptWord, 
			TreeMap<String, String> map, TreeMap<String, String> eMap)
	{	
		int length = 0;
		
		// Reset portion of tree map. 
		for (int i = 0; i < k - 1; i++)
		{
			String eWord = encryptWord[i];
			
				if (eWord.length() <= word.length())
				{
					length = eWord.length();
				} else {
					length = word.length();
				}
				
				for (int j = 0; j < length; j++)
				{
					String eChar = eWord.substring(j, j+1);
					String wChar = word.substring(j, j+1);
					
					if (!eChar.equals(wChar))
					{
						// reset
						map.put(wChar, null);	
					}
				}
		}
		
		// Set word to null.
		eMap.put(word, null);
		solArray[k] = null;
	}
	
	
	boolean isSolution(String[] solArray, int k, TreeMap<String, String> AlphaMap) 
	{
		boolean done = false;
		
		// Verify that the solution array is filled.
		for (int index = 1; index < solArray.length; index++)
		{
			if (solArray[index] == null)
			{
				return false;
			}
		}
		
		DONE = true;
		
		return true;
	}
	
	void printSolution(String [] solArray)
	{
		for (int i = 1; i < solArray.length; i++)
		{
			System.out.print(solArray[i] + " ");
		}
		System.out.println();
	}
}